

package com.mt.restaurant.controller.sale;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.sale.AddressEditDto;
import com.mt.restaurant.entity.sale.Address;
import com.mt.restaurant.service.sale.AddressService;
																		

@Api(tags = "地址")
@RestController
@RequestMapping("/api/restaurant/sale/Address")
@CrossOrigin(allowCredentials = "true")
public class AddressController {
private static Logger logger = LoggerFactory.getLogger(AddressController.class);



																																																									@Autowired private AddressService addressService;
	
	/**
	* 根据分页参数查询地址集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("分页查询地址")
	@ApiPageParam
	@PostMapping("/findAddresss")
	public PageResultDTO findAddresss(@RequestBody PageDTO pageDTO){
		return this.addressService.findAddresss(pageDTO);
	}

	/**
	* 根据ID查询指定的地址
	*
	* @param addressId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("根据id查询地址")
	@ApiPageParam
	@PostMapping("/findAddress")
	public Address findAddress(@RequestParam Long addressId){
		return this.addressService.findAddress(addressId);
	}

	/**
	* 根据ID查询指定的地址(包含外键名称)
	*
	* @param addressId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("根据ID查询指定的地址(包含外键名称)")
	@PostMapping("/findAddressForView")
	public Address findAddressForView(@RequestParam Long addressId){
		return this.addressService.findAddressWithForeignName(addressId);
	}

	/**
	* 根据ID查询指定的地址(包含地址和外键名称)
	*
	* @param addressId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("根据ID查询指定的地址(包含地址和外键名称)")
	@PostMapping("/findAddressForEdit")
	public AddressEditDto findAddressForEdit(@RequestParam Long addressId){
				AddressEditDto addressEditDto = new AddressEditDto();
		addressEditDto.setAddress(this.addressService.findAddressWithForeignName(addressId));

		this.prepareAddressEditDto(addressEditDto);

		return addressEditDto;
	}

	/**
	* 根据ID查询指定的地址(只提取ID 和 Name)
	*
	* @param addressId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("根据ID查询指定的地址(只提取ID 和 Name)")
	@PostMapping("/findAddresssWithIdNameById")
	public Address findAddresssWithIdNameById(@RequestParam Long addressId){
	return this.addressService.findAddresssWithIdNameById(addressId);
	}

	/**
	* 根据名称查询地址集合(只提取ID 和 Name)
	*
	* @param addressName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:view')")
	@ApiOperation("根据名称查询地址集合(只提取ID 和 Name)")
	@PostMapping("/findAddresssWithIdNameByName")
	public List<Address> findAddresssWithIdNameByName(@RequestParam String addressName){
	return this.addressService.findAddresssWithIdNameByName(addressName);
	}


	/**
	* 创建新的地址
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:add')")
	@ApiOperation("创建新的地址")
	@PostMapping("/createAddress")
	public AddressEditDto createAddress(){
				AddressEditDto addressEditDto = new AddressEditDto();
		addressEditDto.setAddress(new Address());

		this.prepareAddressEditDto(addressEditDto);
		return addressEditDto;
	}

	private void prepareAddressEditDto(AddressEditDto addressEditDto){
																																																								}

	/**
	* 新增保存地址
	*
	* @param address 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:add')")
	@ApiOperation("新增保存地址")
	@PostMapping("/saveAddress")
	public Address saveAddress(@RequestBody Address address){
		return this.addressService.saveAddress(address);
	}

	/**
	* 修改保存地址
	*
	* @param address 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:update')")
	@ApiOperation("修改保存地址")
	@PostMapping("/updateAddress")
	public Address updateAddress(@RequestBody Address address){
		return this.addressService.updateAddress(address);
	}

	/**
	* 根据ID删除地址
	*
	* @param addressId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:Address:remove')")
	@ApiOperation("根据ID删除地址")
	@PostMapping("/deleteAddress")
	public void deleteAddress(@RequestParam Long addressId){
		this.addressService.deleteAddress(addressId);
	}



}

